<template>
  <div class="shopList-container">
    <div class="item-container" v-for="item in shopList" :key="item.id" @click="jump(item.id)">
      <img :src="item.img_url" alt="">
      <h2 class="title">{{ item.title }}</h2>
      <div class="price-container">
        <p class="price">
          <span class="now">￥{{ item.now_price }}</span>
          <del class="old">￥{{ item.old_price }}</del>
        </p>
        <p class="num-container">
          <span class="hot">热卖中</span>
          <span class="num">剩{{ item.num }}件</span>
        </p>
      </div>
    </div>
    <mt-button type="danger" size="large" @click="getShopList()">加载更多</mt-button>
  </div>
</template>

<script>
export default {
  data(){
    return {
      shopList:[],
      pageIndex:0
    }
  },
  created(){
    this.getShopList()
  },
  methods:{
    async getShopList(){
      this.pageIndex++
      let data = await this.ajax.get(`/api/shopList?pageIndex=${this.pageIndex}`)
      this.shopList=this.shopList.concat(data.data)
    },
    jump(id){
      this.$router.push(`/home/shopInfo/${id}`)
    }
  }
}
</script>


<style lang="less" scoped>
.shopList-container{
  padding: 2%;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: space-between;
  .item-container{
    width: 49%;
    border: 1px solid #CCC;
    box-shadow: 0 0 8px #CCC;
    margin:4px 0 ;
    display: flex;
    justify-content: space-between;
    flex-direction: column;
    min-height: 325px;
    img{
      width: 100%;
    }
    .title{
      font-size: 18px;
    }
    .price-container{
      padding: 5px;
      background-color: #CCC;
      .now{
        color: red;
        font-size: 16px;
        font-weight: 600;
        padding-right: 10px;
      }
      .num-container{
        display: flex;
        justify-content: space-between;
      }

    }
  }
}
</style>